<!DOCTYPE html>
<html lang="en">
  <head>
    <title>CoFuture Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
    <script src="../js/lunr.min.js" defer></script>
    <script src="../js/typeahead.jquery.js" defer></script>
    <script src="../js/jazzy.search.js" defer></script>
  </head>
  <body>
    <a name="//apple_ref/swift/Class/CoFuture" class="dashAnchor"></a>
    <a title="CoFuture Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../index.html">SwiftCoroutine 2.1.9 Docs</a> (88% documented)</p>
        <p class="header-right">
          <form role="search" action="../search.json">
            <input type="text" placeholder="Search documentation" data-typeahead>
          </form>
        </p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../index.html">SwiftCoroutine Reference</a>
        <img id="carat" src="../img/carat.png" />
        CoFuture Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Classes/CoChannel.html">CoChannel</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CoChannel/BufferType.html">– BufferType</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CoChannel/Receiver.html">– Receiver</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CoChannel/Sender.html">– Sender</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CoFuture.html">CoFuture</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CoPromise.html">CoPromise</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CoScope.html">CoScope</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Enums/CoChannelError.html">CoChannelError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/CoFutureError.html">CoFutureError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/CoroutineError.html">CoroutineError</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Extensions/DispatchQueue.html">DispatchQueue</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/Publisher.html">Publisher</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/URLSession.html">URLSession</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Protocols/CoCancellable.html">CoCancellable</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/CoroutineScheduler.html">CoroutineScheduler</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Structs/Coroutine.html">Coroutine</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>CoFuture</h1>
              <div class="declaration">
                <div class="language">
                  
                  <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">Value</span><span class="o">&gt;</span></code></pre>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">CoFuture</span><span class="p">:</span> <span class="kt">Hashable</span></code></pre>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">CoFuture</span><span class="p">:</span> <span class="kt"><a href="../Protocols/CoCancellable.html">CoCancellable</a></span></code></pre>

                </div>
              </div>
            <p>Holder for a result that will be provided later.</p>

<p><code>CoFuture</code> and its subclass <code><a href="../Classes/CoPromise.html">CoPromise</a></code> are the implementation of the Future/Promise approach.
They allow to launch asynchronous tasks and immediately return<code>CoFuture</code> with its future results.
The available result can be observed by the <code>whenComplete()</code> callback
or by <code>await()</code> inside a coroutine without blocking a thread.</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">makeFutureOne</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">Response</span><span class="o">&gt;</span> <span class="p">{</span>
    <span class="k">let</span> <span class="nv">promise</span> <span class="o">=</span> <span class="kt">CoPromise</span><span class="o">&lt;</span><span class="kt">Response</span><span class="o">&gt;</span><span class="p">()</span>
    <span class="n">someAsyncFuncWithCallback</span> <span class="p">{</span> <span class="n">response</span> <span class="k">in</span>
        <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="k">do</span> <span class="kd">some</span> <span class="n">work</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
        <span class="n">promise</span><span class="o">.</span><span class="nf">success</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
    <span class="p">}</span>
    <span class="k">return</span> <span class="n">promise</span>
<span class="p">}</span>

<span class="kd">func</span> <span class="nf">makeFutureTwo</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">Response</span><span class="o">&gt;</span> <span class="p">{</span>
    <span class="n">queue</span><span class="o">.</span><span class="n">coroutineFuture</span> <span class="p">{</span>
        <span class="k">let</span> <span class="nv">future</span> <span class="o">=</span> <span class="nf">makeFutureOne</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
        <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="k">do</span> <span class="kd">some</span> <span class="n">work</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
        <span class="k">let</span> <span class="nv">response</span> <span class="o">=</span> <span class="k">try</span> <span class="n">future</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span>
        <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="n">create</span> <span class="n">result</span> <span class="n">using</span> <span class="n">response</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
        <span class="k">return</span> <span class="n">result</span>
    <span class="p">}</span>
 <span class="p">}</span>

<span class="kd">func</span> <span class="nf">performSomeWork</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">let</span> <span class="nv">future</span> <span class="o">=</span> <span class="nf">makeFutureTwo</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
    <span class="n">mainQueue</span><span class="o">.</span><span class="n">startCoroutine</span> <span class="p">{</span>
        <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="k">do</span> <span class="kd">some</span> <span class="n">work</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
        <span class="k">let</span> <span class="nv">result</span> <span class="o">=</span> <span class="k">try</span> <span class="n">future</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span>
        <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="k">do</span> <span class="kd">some</span> <span class="n">work</span> <span class="n">using</span> <span class="n">result</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<p>For coroutine error handling you can use standart <code>do-catch</code> statement or use <code>CoFuture</code> as an alternative.</p>
<pre class="highlight swift"><code><span class="c1">//execute coroutine and return CoFuture&lt;Void&gt; that we will use for error handling</span>
<span class="kt">DispatchQueue</span><span class="o">.</span><span class="n">main</span><span class="o">.</span><span class="n">coroutineFuture</span> <span class="p">{</span>
    <span class="k">let</span> <span class="nv">result</span> <span class="o">=</span> <span class="k">try</span> <span class="nf">makeSomeFuture</span><span class="p">()</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span>
    <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="n">use</span> <span class="n">result</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
<span class="p">}</span><span class="o">.</span><span class="n">whenFailure</span> <span class="p">{</span> <span class="n">error</span> <span class="k">in</span>
    <span class="o">.</span> <span class="o">.</span> <span class="o">.</span> <span class="n">handle</span> <span class="n">error</span> <span class="o">.</span> <span class="o">.</span> <span class="o">.</span>
<span class="p">}</span>
</code></pre>

<p>Apple has introduced a new reactive programming framework <code>Combine</code>
that makes writing asynchronous code easier and includes a lot of convenient and common functionality.
We can use it with coroutines by making <code>CoFuture</code> a subscriber and await its result.</p>
<pre class="highlight swift"><code><span class="c1">//create Combine publisher</span>
<span class="k">let</span> <span class="nv">publisher</span> <span class="o">=</span> <span class="kt">URLSession</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">dataTaskPublisher</span><span class="p">(</span><span class="nv">for</span><span class="p">:</span> <span class="n">url</span><span class="p">)</span><span class="o">.</span><span class="nf">map</span><span class="p">(\</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>

<span class="c1">//execute coroutine on the main thread</span>
<span class="kt">DispatchQueue</span><span class="o">.</span><span class="n">main</span><span class="o">.</span><span class="n">startCoroutine</span> <span class="p">{</span>
    <span class="c1">//subscribe CoFuture to publisher</span>
    <span class="k">let</span> <span class="nv">future</span> <span class="o">=</span> <span class="n">publisher</span><span class="o">.</span><span class="nf">subscribeCoFuture</span><span class="p">()</span>

    <span class="c1">//await data without blocking the thread</span>
    <span class="k">let</span> <span class="nv">data</span><span class="p">:</span> <span class="kt">Data</span> <span class="o">=</span> <span class="k">try</span> <span class="n">future</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span>
<span class="p">}</span>
</code></pre>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC7promiseACyxGyys6ResultOyxs5Error_pGcXE_tcfc"></a>
                    <a name="//apple_ref/swift/Method/init(promise:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC7promiseACyxGyys6ResultOyxs5Error_pGcXE_tcfc">init(promise:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Initializes a future that invokes a promise closure.</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">someAsyncFunc</span><span class="p">(</span><span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Int</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>

<span class="k">let</span> <span class="nv">future</span> <span class="o">=</span> <span class="kt">CoFuture</span><span class="p">(</span><span class="nv">promise</span><span class="p">:</span> <span class="n">someAsyncFunc</span><span class="p">)</span>
</code></pre>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">(</span><span class="nv">promise</span><span class="p">:</span> <span class="p">(</span><span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>promise</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>A closure to fulfill this future.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC4taskACyxGxyKc_tcfc"></a>
                    <a name="//apple_ref/swift/Method/init(task:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC4taskACyxGxyKc_tcfc">init(task:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Starts a new coroutine and initializes future with its result.</p>
<div class="aside aside-note">
    <p class="aside-title">Note</p>
    If you cancel this <code>CoFuture</code>, it will also cancel the coroutine that was started inside of it.

</div>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">sum</span><span class="p">(</span><span class="nv">future1</span><span class="p">:</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">Int</span><span class="o">&gt;</span><span class="p">,</span> <span class="nv">future2</span><span class="p">:</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">Int</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">Int</span><span class="o">&gt;</span> <span class="p">{</span>
    <span class="kt">CoFuture</span> <span class="p">{</span> <span class="k">try</span> <span class="n">future1</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span> <span class="o">+</span> <span class="n">future2</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span> <span class="p">}</span>
<span class="p">}</span>
</code></pre>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">(</span><span class="nv">task</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Value</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>task</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The closure that will be executed inside the coroutine.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC6resultACyxGs6ResultOyxs5Error_pG_tcfc"></a>
                    <a name="//apple_ref/swift/Method/init(result:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC6resultACyxGs6ResultOyxs5Error_pG_tcfc">init(result:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Initializes a future with result.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">convenience</span> <span class="nf">init</span><span class="p">(</span><span class="nv">result</span><span class="p">:</span> <span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>result</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The result provided by this future.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/result"></a>
                <a name="//apple_ref/swift/Section/result" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/result"></a>
                  <h3 class="section-name"><p>result</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC6results6ResultOyxs5Error_pGSgvp"></a>
                    <a name="//apple_ref/swift/Property/result" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC6results6ResultOyxs5Error_pGSgvp">result</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Returns completed result or nil if this future has not been completed yet.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">result</span><span class="p">:</span> <span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">?</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/cancel"></a>
                <a name="//apple_ref/swift/Section/cancel" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/cancel"></a>
                  <h3 class="section-name"><p>cancel</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC10isCanceledSbvp"></a>
                    <a name="//apple_ref/swift/Property/isCanceled" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC10isCanceledSbvp">isCanceled</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Returns <code>true</code> when the current future is canceled.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="k">var</span> <span class="nv">isCanceled</span><span class="p">:</span> <span class="kt">Bool</span> <span class="p">{</span> <span class="k">get</span> <span class="p">}</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC6cancelyyF"></a>
                    <a name="//apple_ref/swift/Method/cancel()" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC6cancelyyF">cancel()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Cancels the current future.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">cancel</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/await"></a>
                <a name="//apple_ref/swift/Section/await" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/await"></a>
                  <h3 class="section-name"><p>await</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC5awaitxyKF"></a>
                    <a name="//apple_ref/swift/Method/await()" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC5awaitxyKF">await()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Await for the result of this <code>CoFuture</code> without blocking the current thread. Must be called inside a coroutine.</p>
<pre class="highlight swift"><code><span class="c1">//execute someSyncFunc() on global queue and return its future result</span>
<span class="k">let</span> <span class="nv">future</span> <span class="o">=</span> <span class="kt">DispatchQueue</span><span class="o">.</span><span class="nf">global</span><span class="p">()</span><span class="o">.</span><span class="n">coroutineFuture</span> <span class="p">{</span> <span class="nf">someSyncFunc</span><span class="p">()</span> <span class="p">}</span>
<span class="c1">//start coroutine on main thread</span>
<span class="kt">DispatchQueue</span><span class="o">.</span><span class="n">main</span><span class="o">.</span><span class="n">startCoroutine</span> <span class="p">{</span>
    <span class="c1">//await result of future</span>
    <span class="k">let</span> <span class="nv">result</span> <span class="o">=</span> <span class="k">try</span> <span class="n">future</span><span class="o">.</span><span class="nf">await</span><span class="p">()</span>
<span class="p">}</span>
</code></pre>
<div class="aside aside-throws">
    <p class="aside-title">Throws</p>
    The failed result of the <code>CoFuture</code>.

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">await</span><span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Value</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>The value of the <code>CoFuture</code> when it is completed.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC5await7timeoutx8Dispatch0G12TimeIntervalO_tKF"></a>
                    <a name="//apple_ref/swift/Method/await(timeout:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC5await7timeoutx8Dispatch0G12TimeIntervalO_tKF">await(timeout:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Await for the result of this <code>CoFuture</code> without blocking the current thread. Must be called inside a coroutine.</p>
<div class="aside aside-throws">
    <p class="aside-title">Throws</p>
    The failed result of the <code>CoFuture</code>.

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">await</span><span class="p">(</span><span class="nv">timeout</span><span class="p">:</span> <span class="kt">DispatchTimeInterval</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Value</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>timeout</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The time interval to await for a result.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>The value of the <code>CoFuture</code> when it is completed.</p>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/map"></a>
                <a name="//apple_ref/swift/Section/map" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/map"></a>
                  <h3 class="section-name"><p>map</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC3mapyACyqd__Gqd__xKclF"></a>
                    <a name="//apple_ref/swift/Method/map(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC3mapyACyqd__Gqd__xKclF">map(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>When future is fulfilled, run the provided callback, which performs a synchronous computation and return transformed value.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="n">map</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">transform</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Value</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">NewValue</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>transform</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Function that will receive the value and return a new transformed value or throw an error.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A future that will receive the eventual value.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC7recoveryACyxGxs5Error_pKcF"></a>
                    <a name="//apple_ref/swift/Method/recover(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC7recoveryACyxGxs5Error_pKcF">recover(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>When future is in an error state, run the provided callback, which can recover from the error and return a new value.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">recover</span><span class="p">(</span><span class="n">_</span> <span class="nv">transform</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Error</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Value</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>transform</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Function that will receive the error and return a new value or throw an error.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A future that will receive the recovered value.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC9mapResultyACyqd__Gs0F0Oyqd__s5Error_pGAGyxsAH_pGclF"></a>
                    <a name="//apple_ref/swift/Method/mapResult(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC9mapResultyACyqd__Gs0F0Oyqd__s5Error_pGAGyxsAH_pGclF">mapResult(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>When future is fulfilled, run the provided callback, which performs a synchronous computation and return transformed result.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">mapResult</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">transform</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Result</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>transform</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Function that will receive the result and return a new transformed result.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A future that will receive the eventual result.</p>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/flatMap"></a>
                <a name="//apple_ref/swift/Section/flatMap" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/flatMap"></a>
                  <h3 class="section-name"><p>flatMap</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC7flatMapyACyqd__GAExclF"></a>
                    <a name="//apple_ref/swift/Method/flatMap(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC7flatMapyACyqd__GAExclF">flatMap(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>When the current <code>CoFuture</code> is fulfilled, run the provided callback, which will provide a new <code>CoFuture</code>.</p>

<p>This allows you to dynamically dispatch new asynchronous tasks as phases in a
longer series of processing steps. Note that you can use the results of the
current <code>CoFuture</code> when determining how to dispatch the next operation.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="n">flatMap</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Value</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Function that will receive the value and return a new <code>CoFuture</code>.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A future that will receive the eventual value.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC12flatMapErroryACyxGAEs0G0_pcF"></a>
                    <a name="//apple_ref/swift/Method/flatMapError(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC12flatMapErroryACyxGAEs0G0_pcF">flatMapError(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>When the current <code>CoFuture</code> is in an error state, run the provided callback, which
may recover from the error by returning a <code>CoFuture</code>.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">flatMapError</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Error</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Function that will receive the error value and return a new value lifted into a new <code>CoFuture</code>.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A future that will receive the recovered value.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC13flatMapResultyACyqd__GAEs0G0Oyxs5Error_pGclF"></a>
                    <a name="//apple_ref/swift/Method/flatMapResult(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC13flatMapResultyACyqd__GAEs0G0Oyxs5Error_pGclF">flatMapResult(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>When the current <code>CoFuture</code> is fulfilled, run the provided callback, which will provide a new <code>CoFuture</code>.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">flatMapResult</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">CoFuture</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Function that will receive the result and return a new <code>CoFuture</code>.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A future that will receive the eventual value.</p>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/whenComplete"></a>
                <a name="//apple_ref/swift/Section/whenComplete" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/whenComplete"></a>
                  <h3 class="section-name"><p>whenComplete</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC12whenCompleteyyys6ResultOyxs5Error_pGcF"></a>
                    <a name="//apple_ref/swift/Method/whenComplete(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC12whenCompleteyyys6ResultOyxs5Error_pGcF">whenComplete(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds an observer callback that is called when the <code>CoFuture</code> has any result.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">whenComplete</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Result</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback that is called when the <code>CoFuture</code> is fulfilled.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC11whenSuccessyyyxcF"></a>
                    <a name="//apple_ref/swift/Method/whenSuccess(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC11whenSuccessyyyxcF">whenSuccess(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds an observer callback that is called when the <code>CoFuture</code> has a success result.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">whenSuccess</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Value</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback that is called with the successful result of the <code>CoFuture</code>.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC11whenFailureyyys5Error_pcF"></a>
                    <a name="//apple_ref/swift/Method/whenFailure(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC11whenFailureyyys5Error_pcF">whenFailure(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds an observer callback that is called when the <code>CoFuture</code> has a failure result.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">whenFailure</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Error</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback that is called with the failed result of the <code>CoFuture</code>.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC12whenCanceledyyyycF"></a>
                    <a name="//apple_ref/swift/Method/whenCanceled(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC12whenCanceledyyyycF">whenCanceled(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds an observer callback that is called when the <code>CoFuture</code> is canceled.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">whenCanceled</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback that is called when the <code>CoFuture</code> is canceled.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC12whenCompleteyyyycF"></a>
                    <a name="//apple_ref/swift/Method/whenComplete(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC12whenCompleteyyyycF">whenComplete(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds an observer callback that is called when the <code>CoFuture</code> has any result.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">whenComplete</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The callback that is called when the <code>CoFuture</code> is fulfilled.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/hashable"></a>
                <a name="//apple_ref/swift/Section/hashable" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/hashable"></a>
                  <h3 class="section-name"><p>hashable</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:SQ2eeoiySbx_xtFZ"></a>
                    <a name="//apple_ref/swift/Method/==(_:_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:SQ2eeoiySbx_xtFZ">==(_:<wbr>_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="o">==</span> <span class="p">(</span><span class="nv">lhs</span><span class="p">:</span> <span class="kt">CoFuture</span><span class="p">,</span> <span class="nv">rhs</span><span class="p">:</span> <span class="kt">CoFuture</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:SH4hash4intoys6HasherVz_tF"></a>
                    <a name="//apple_ref/swift/Method/hash(into:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:SH4hash4intoys6HasherVz_tF">hash(into:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">@inlinable</span>
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">hash</span><span class="p">(</span><span class="n">into</span> <span class="nv">hasher</span><span class="p">:</span> <span class="k">inout</span> <span class="kt">Hasher</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/publisher"></a>
                <a name="//apple_ref/swift/Section/publisher" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/publisher"></a>
                  <h3 class="section-name"><p>publisher</p>
</h3>
                </div>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:14SwiftCoroutine8CoFutureC9publisher7Combine12AnyPublisherVyxs5Error_pGyF"></a>
                    <a name="//apple_ref/swift/Method/publisher()" class="dashAnchor"></a>
                    <a class="token" href="#/s:14SwiftCoroutine8CoFutureC9publisher7Combine12AnyPublisherVyxs5Error_pGyF">publisher()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Returns a publisher that emits result of this <code>CoFuture</code>.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">publisher</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">AnyPublisher</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">Error</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2020 <a class="link" href="https://github.com/belozierov/SwiftCoroutine" target="_blank" rel="external">Alex Belozierov</a>. All rights reserved. (Last updated: 2020-07-11)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.5</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
